package alipay

import (
	"golang.org/x/exp/slices"
	"strings"
)

// 支付宝biz_content
type Values map[string]string

func (v Values) Set(key string, value string) {
	v[key] = value
}

// 升序排序+拼接
func (v Values) FormatParams() string {
	if len(v) <= 0 {
		return ""
	}
	var buf []string
	for key, val := range v {
		if len(val) <= 0 {
			continue
		}
		buf = append(buf, key+"="+val)
	}
	slices.Sort(buf)
	paramString := strings.Join(buf, "&")
	return paramString
}
